import { ITodoVm, Level } from './todo-list.model';

export class TodoParams implements ITodoParams {

  constructor(data?: ITodoParams) {
      if (data) {
          for (const property in data) {
              if (data.hasOwnProperty(property)) {
                  (<any>this)[property] = (<any>data)[property];
              }
          }
      }
  }
  content!: string;
  level?: Level | null;

  static fromJS(data: any): TodoParams {
      data = typeof data === 'object' ? data : {};
      const result = new TodoParams();
      result.init(data);
      return result;
  }

  init(data?: any) {
      if (data) {
          this.content = data['content'] !== undefined ? data['content'] : <any>null;
          this.level = data['level'] !== undefined ? data['level'] : <any>null;
      }
  }

  toJSON(data?: any) {
      data = typeof data === 'object' ? data : {};
      data['content'] = this.content !== undefined ? this.content : <any>null;
      data['level'] = this.level !== undefined ? this.level : <any>null;
      return data;
  }
}

export interface ITodoParams {
  content: string;
  level?: Level | null;
}

export class TodoVm implements ITodoVm {

  constructor(data?: ITodoVm) {
      if (data) {
          for (const property in data) {
              if (data.hasOwnProperty(property)) {
                  (<any>this)[property] = (<any>data)[property];
              }
          }
      }
  }
  createdAt?: Date | null;
  updatedAt?: Date | null;
  id?: string | null;
  content!: string;
  level!: Level;
  isCompleted!: boolean;

  static fromJS(data: any): TodoVm {
      data = typeof data === 'object' ? data : {};
      const result = new TodoVm();
      result.init(data);
      return result;
  }

  init(data?: any) {
      if (data) {
          this.createdAt = data['createdAt'] ? new Date(data['createdAt'].toString()) : <any>null;
          this.updatedAt = data['updatedAt'] ? new Date(data['updatedAt'].toString()) : <any>null;
          this.id = data['id'] !== undefined ? data['id'] : <any>null;
          this.content = data['content'] !== undefined ? data['content'] : <any>null;
          this.level = data['level'] !== undefined ? data['level'] : <any>null;
          this.isCompleted = data['isCompleted'] !== undefined ? data['isCompleted'] : <any>null;
      }
  }

  toJSON(data?: any) {
      data = typeof data === 'object' ? data : {};
      data['createdAt'] = this.createdAt ? this.createdAt.toISOString() : <any>null;
      data['updatedAt'] = this.updatedAt ? this.updatedAt.toISOString() : <any>null;
      data['id'] = this.id !== undefined ? this.id : <any>null;
      data['content'] = this.content !== undefined ? this.content : <any>null;
      data['level'] = this.level !== undefined ? this.level : <any>null;
      data['isCompleted'] = this.isCompleted !== undefined ? this.isCompleted : <any>null;
      return data;
  }
}
